var hasOwnProperty = Object.prototype.hasOwnProperty;
var slice = Array.prototype.slice;
var nativeForEach = Array.prototype.forEach;
var _ = {};

var each = _.each = _.forEach = function (obj, iterator, context) {
  if (obj == null)
    return;
  if (nativeForEach && obj.forEach === nativeForEach) {
    obj.forEach(iterator, context);
  } else if (obj.length === +obj.length) {
    for (var i = 0, l = obj.length; i < l; i++) {
      if (i in obj && iterator.call(context, obj[i], i, obj) === breaker)
        return;
    }
  } else {
    for (var key in obj) {
      if (_.has(obj, key)) {
        if (iterator.call(context, obj[key], key, obj) === breaker)
          return;
      }
    }
  }
}

_.has = function (obj, key) {
  return hasOwnProperty.call(obj, key);
};

_.extend = function (obj) {
  each(slice.call(arguments, 1), function (source) {
    for (var prop in source) {
      obj[prop] = source[prop];
    }
  });
  return obj;
};

var extend = function (protoProps, staticProps) {
  var parent = this;
  var child;
  if (protoProps && _.has(protoProps, 'constructor')) {
    child = protoProps.constructor;
  } else {
    child = function () { return parent.apply(this, arguments); };
  }
  _.extend(child, parent, staticProps);
  var Surrogate = function () { this.constructor = child; };
  Surrogate.prototype = parent.prototype;
  child.prototype = new Surrogate;
  if (protoProps) _.extend(child.prototype, protoProps);
  child.__super__ = parent.prototype;
  return child;
};


var P = function () {
  this.a = 1;
  this.b = 2;
};

P.prototype.aa = function () {
  alert(this.a);
}

P.extend = extend;

var C = P.extend({
  c: 3,
  cc: function () {
    alert(this.c);
  }
});

var s = '';